#ifndef LED_H_
#define LED_H_

typedef struct GPIO_pin_t {
	unsigned char port;
    unsigned int pin;
    unsigned char lastValue;
    struct GPIO_pin_t * next;
} GPIO_pin_t;

//extern struct led_t;
//typedef struct led_t * led_p;
//extern const unsigned int led2_t_size;
//typedef char led2_t_holder[led2_t_size];

/*
typedef struct led_t {
	GPIO_pin_t pin;
	unsigned int tick;
	unsigned int tick_load;
} led_t;
*/

enum RATES {
	RATE_OFF,
	RATE_BEGIN=RATE_OFF,
	RATE_ON,
	RATE_SLOW_SLOW,
	RATE_SLOW,
	RATE_FAST,
	RATE_END
};
enum LED_ORDER {
	MSB,
	LSB
};

enum LED_INDEX {
	LED_Begin = 0,
	LED_local_begin = LED_Begin,
	LED_noGlobalAlmLed = LED_Begin,
	LED_SI_1_Alm = LED_Begin, //0
	LED_SI_2_Alm,
	LED_SI_3_Alm,
	LED_SI_4_Alm,
	LED_SI_5_Alm,
	LED_SI_6_Alm,
	LED_SI_7_Alm,
	LED_SI_8_Alm, // 7
	LED_SI_1_Flt, // 8
	LED_SI_2_Flt,
	LED_SI_3_Flt,
	LED_SI_4_Flt,
	LED_SI_5_Flt,
	LED_SI_6_Flt,
	LED_SI_7_Flt,
	LED_SI_8_Flt, // 15
	LED_SO_1_Alm,
	LED_SO_2_Alm,
	LED_SO_3_Alm,
	LED_SO_4_Alm,
	LED_SO_5_Alm,
	LED_SO_6_Alm,
	LED_SO_7_Alm,
	LED_SO_8_Alm, //23
	LED_SO_1_Flt,
	LED_SO_2_Flt,
	LED_SO_3_Flt,
	LED_SO_4_Flt,
	LED_SO_5_Flt,
	LED_SO_6_Flt,
	LED_SO_7_Flt,
	LED_SO_8_Flt, // 31
	LED_local_end = LED_SO_8_Flt,
//	LED_UNUSED,
	LED_PANEL,
	LED_GA_SILENCE,
	LED_TROUBLE,
	LED_WARNING,
	LED_SERVICE_MODE,
	LED_SUPER,
	LED_GROUND,
	LED_STANDBY, // 39
	LED_PRIMARY,
//	OSO_4,
//	OSO_3,
//	OSO_2,
//	OSO_1,
	LED_ALARMS, // 41
//	LED_ALARM_2,
	LED_end=LED_ALARMS,
	LED_LAST
};
enum LED_GLOBAL_INDEX {
	LED_GLOBAL_INVALID=-1,
	LED_GLOBAL_BEGIN=0,
	LED_GLOBAL_PANEL=0,
	LED_GLOBAL_GA_SILENCE=1,
	LED_GLOBAL_TROUBLE=2,
	LED_GLOBAL_WARNING=3,
	LED_GLOBAL_SERVICE_MODE=4,
	LED_GLOBAL_SUPER=5,
	LED_GLOBAL_GROUND=6,
	LED_GLOBAL_STANDBY=7, // 39
	LED_GLOBAL_PRIMARY=8,
//	OSO_4,
//	OSO_3,
//	OSO_2,
//	OSO_1,
	LED_GLOBAL_ALARMS=9, // 41
	LED_GLOBAL_END = LED_GLOBAL_ALARMS,
//	LED_ALARM_2,
	LED_GLOBAL_LAST
};
enum LED_GLOBAL_INDEX globalLedToIndex(enum LED_INDEX led);

enum LED_State {
	LED_PORT_ALL_ON,
	LED_OFF,
	LED_PORT_ALL_OFF=0xFF
};
enum e_mode {
	MODE_NORMAL=0,
	MODE_SERVICE=1,
	MODE_LAMP_TEST=2
};
//void LED_init(led_p led, unsigned char _port, unsigned int _pin);
void LED_init(void);
void LED_thread(void);
void LED_updateTimer(void);

int 		LED_setRateRange(enum LED_INDEX begin, enum LED_INDEX end, enum RATES rate);
void 		LED_setRate(enum LED_INDEX index, enum RATES rate);
void 		LED_resourceArray_init(unsigned char max, enum LED_INDEX firstResource);
int 		LED_resourceArray_requestRate(enum LED_GLOBAL_INDEX resourceIndex, enum LED_INDEX requestorIndex, enum RATES newRate);
int 		LED_resourceArray_requestRateRange(enum LED_GLOBAL_INDEX resourceIndexBegin, enum LED_GLOBAL_INDEX resourceIndexEnd, enum LED_INDEX requestorIndex, enum RATES newRate);
int 		LED_resourceArray_processLED(void);
enum RATES 	LED_getRate(enum LED_INDEX index);
int 		LED_areAnyRatesSet(enum LED_INDEX beg, enum LED_INDEX end);

void LED_setMode(enum e_mode mode);
void LED_updateTickSendMsg(unsigned char bytes);

/*void LED_off(led_p led);
void LED_on(led_p led);*/
//void LED_thread_BuzzerHelper(unsigned char rate);
void LED_buzzerLogic(void);
enum RATES LED_Buzzer_getRate(void);
void LED_thread_BuzzerHelper(enum RATES rate);

void 			SO_out_init(void); // this doesn't belong here
unsigned char 	SO_out_getLastOSOon(void);
unsigned char 	SO_out_getLastLEDon(void);
void 			LED_test_marshalLEDperI2CportSOREL(void);
void I2C_SO_setStatus(unsigned char  status);
unsigned char I2C_SO_getStatus(void);


#endif /* LED_H_ */
